package cn.edu.nju.ws.sview.reasoning.magicsets;

import java.util.ArrayList;

import cn.edu.nju.ws.sview.rdf.Resource;
import cn.edu.nju.ws.sview.reasoning.Predicate;

/**
 * @author Gong Saisai
 * MagicPredicate, AdornedPredicate construction
 * 
 */
public class MagicSetsFactory {
    private static MagicSetsFactory instance = null;

	private MagicSetsFactory() {
	}

	private synchronized static void init() {
		instance = new MagicSetsFactory();
	}

	public static MagicSetsFactory getInstance() {
		if (instance == null) {
			init();
		}
		return instance;
	}

	public MagicPredicate createMagicPredicate(Resource resource, int arity,
			BoundFree[] adornment) {
		return new MagicPredicate(resource, arity, adornment);
	}

	public AdornedPredicate createAdornedPredicate(Predicate pred,
			ArrayList<Integer> constIndex) {
		BoundFree[] adornment = new BoundFree[pred.getArity()];
		for (int i = 0; i < pred.getArity(); i++) {
			if (constIndex.contains(i)) {
				adornment[i] = BoundFree.BOUND;
			} else
				adornment[i] = BoundFree.FREE;
		}
		return new AdornedPredicate(pred, adornment);
	}
}
